package com.yegs.jltqc.U8Controller;

import com.yegs.jltqc.U8Service.QmilcodeService;
import com.yegs.jltqc.config.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/qmilcode")
public class QmilcodeController {

    @Autowired
    private QmilcodeService qmilcodeService;

    @GetMapping("/findAll")
    public Msg findAll(){
        return Msg.success("data",qmilcodeService.findAll());
    }

    @GetMapping("/get")
    public Msg get(@RequestParam(required = true) String level,@RequestParam(required = true) Float qty,@RequestParam(required = true) Double grade){
        if(qty < 2){
            return Msg.error("质检数量不能小于2");
        }
        return Msg.success("data",qmilcodeService.getCodeByLevelAndQtyAndGrade(level,qty,grade));
    }

    @GetMapping("/findDemoByLevelAndQty")
    public Msg findDemoByLevelAndQty(@RequestParam(required = true) String level,@RequestParam(required = true) Float qty){
        if(qty < 2){
            return Msg.error("质检数量不能小于2");
        }
        return Msg.success("data",qmilcodeService.findDemoByLevelAndQty(level,qty));
    }
}
